package pers.cz.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.sql.DataSource;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * 使用dbcpl连接池
 * @program: postgirl-collection-client
 * @description: DatabasePools
 * @author: Cheng Zhi
 * @create: 2022-03-07 18:07
 **/
public class DatabasePools {

    private static Logger logger = LoggerFactory.getLogger(DatabasePools.class);
    private static Properties properties = new Properties();
    private static DataSource dataSource;

    //从连接池中获取一个连接
    public static Connection getConnection(){
        Connection connection = null;
        try{
            connection = dataSource.getConnection();
        }catch(SQLException e){
            logger.error("get datasource excepiton", e);
        }
        try {
            connection.setAutoCommit(false);
        } catch (SQLException e) {
            logger.error("datasource set auto commit failed!", e);
        }
        return connection;
    }
}
